/*
参数说明：
  isList-传过来的数组，在组件内部做循环操作
  isMoney-是否显示金钱占位
  isScore-是否显示积分占位
  isRemove-是否显示购买按钮占位
  divsize-组件一排显示几个数据
  biaoqian-跳转积分详情还是商品详情界面(1 积分兑换界面  2 商品详情界面)
*/
<template>
  <div >
    <alert v-model="alertShow.showmsg" :title="'提示'" @on-show="onShow" @on-hide="onHide">{{alertShow.msg}}</alert>
    <flexbox :gutter="0" wrap="wrap">
      <flexbox-item :span="divsize" v-for="item in isList" style="padding-top: 5px">
        <div class="flex-demo">
          <div style="margin: 0 5px 5px;border: 1px solid #f1f7ff;background-color: #ffffff">
            <div @click="shopinfoFn(item)">
              <div>
                <img :src="item.url" width="100%" >
                <!--<img src="http://qiuniu.xingrui-cn.com/297429397860777984.jpg" width="100%"/>-->
              </div>
              <div style="height: 40px">
                <flexbox :gutter="0" wrap="nowrap">
                  <flexbox-item>
                    <h5 style="padding-left: 10px;font-size: 11px;color: #636363">{{item.name}}</h5>
                  </flexbox-item>
                  <!--<flexbox-item :span="3" v-if="isRemove">-->
                  <!--<img @click="addShopCar(item)" src="../../../src/assets/images/shopMall/shopInfoIcon.png" width="100%" >-->
                  <!--</flexbox-item>-->
                </flexbox>
                <!--<h5 style="padding-left: 5px;padding-right: 5px;font-size: 11px;color: #636363">{{item.name}}</h5>-->
              </div>
            </div>
            <div>
              <flexbox :gutter="0" wrap="nowrap">
                <flexbox-item :span="12" v-if="isScore"><p style="font-size: 15px;color: #fa0000;padding-left: 3px">{{item.pointPrice}}积分</p></flexbox-item>
                <flexbox-item :span="12" v-if="isMoney">
                  <p style="font-size: 15px;text-align:left;color: #fa0000;display: inline-block">￥{{item.nowPrice}}</p>
                  <p v-if="item.oldPrice !== undefined && item.oldPrice > 0" style="font-size: 12px;text-decoration: line-through;text-align: left;color: #999999;display: inline-block">￥{{item.oldPrice}}</p>
                </flexbox-item>
                <!--<flexbox-item :span="3" v-if="isRemove">-->
                  <!--<img @click="addShopCar(item)" src="../../../src/assets/images/shopMall/shopInfoIcon.png" width="100%" >-->
                <!--</flexbox-item>-->
              </flexbox>
            </div>
          </div>
        </div>
      </flexbox-item>
    </flexbox>
  </div>
</template>
<script>
  import { Flexbox, FlexboxItem, XImg, Alert } from 'vux'
  import * as urls from '../../api/urls'

  export default {
    components: {
      Flexbox,
      FlexboxItem,
      XImg,
      Alert
    },
    props: {
      isList: {
        type: Array,
        default: []
      },
      isMoney: {
        type: Boolean,
        default: false
      },
      isScore: {
        type: Boolean,
        default: false
      },
      isRemove: {
        type: Boolean,
        default: false
      },
      divsize: {
        type: Number,
        default: 6
      },
      biaoqian: {
        type: Number,
        default: 6
      }
    },
    mounted: function () {
    },
    data () {
      return {
        alertShow: {
          showmsg: false,
          msg: ''
        }
      }
    },
    methods: {
      addShopCar (item) {
        let userId = window.sessionStorage.getItem('userId')
        let that = this
        this.http(urls.addToCart, {userId: userId, itemId: parseInt(item.shopId)}, function (res) {
          if (res.status === 100) {
            that.$vux.alert.show({
              title: '提示',
              content: '已添加商品' + item.name + '至您的购物车中'
            })
          } else {
            that.$vux.alert.show({
              title: '提示',
              content: res.errMsg
            })
          }
        }, function (res) {
          that.$vux.alert.show({
            title: '提示',
            content: res
          })
        })
      },
      shopinfoFn (item) {
        // 1 积分兑换界面  2 商品详情界面
        let type = this.biaoqian
        if (type === 1) {
          window.sessionStorage.setItem('shopId', item.itemId)
          let userId = window.sessionStorage.getItem('userId')
          window.location.href = '/api/wxAuth/go/ScoreShop_id=' + item.itemId + '&userId=' + userId
        } else if (type === 2) {
          window.sessionStorage.setItem('shopId', item.shopId)
          let userId = window.sessionStorage.getItem('userId')
          window.location.href = '/api/wxAuth/go/ShopInfo_id=' + item.shopId + '&userId=' + userId
//          this.$router.push({
//            path: '/ShopInfo'
//          })
        } else if (type === 3) {
          let that = this
          window.sessionStorage.setItem('shopId', item.shopId)
          that.http(urls.clickNumber, {id: item.shopId}, function (res) {
            if (res.status === 100) {
              window.location.reload()
            } else {
              that.alertShow.showmsg = true
              that.alertShow.msg = res.errMsg
            }
          }, function (res) {
            that.alertShow.showmsg = true
            that.alertShow.msg = res
          })
        }
      },
      onShow () {
        // 弹窗出现时触发
      },
      onHide () {
        // 弹窗关闭时触发
      }
    }
  }
</script>
